package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/teachers")
public class TeacherController {

    @GetMapping("/courses")
    public String teacherCourses(Model model, HttpSession session) {
        // 检查登录状态和用户类型
        if (session.getAttribute("loggedIn") == null || !"teacher".equals(session.getAttribute("userType"))) {
            return "redirect:/index";
        }

        model.addAttribute("username", session.getAttribute("username"));
        model.addAttribute("userType", session.getAttribute("userType"));
        return "teacher"; // 返回教师视图
    }

    @RequestMapping("/course")
    public String teachercourse(Model model, HttpSession session) {
        System.out.println("7777777777777");
        // 需要查询课程数据，然后存到model，然后重定向课程的页面
        return "/course/list";
    }
}